<?php
$conn = @mysqli_connect('192.168.10.123', 'root', '123456', 'bbs', 13306);
if (!$conn) {// 检查是否连接成功 也可以使用mysqli_connect_errno()判断
    die("连接数据库错误: " . mysqli_connect_error());
}
mysqli_query($conn,'set names utf8');
$sql = "insert into users (username,age,sex) values(?,?,?)"; //需要执行的SQL语句
$stmt = mysqli_prepare($conn,$sql); // 预处理SQL 注意后续所有操作需要此数据
mysqli_stmt_bind_param($stmt,'sis',$username,$age,$sex);

$username = '张磊';
$age = 22;
$sex = '男';
$result = mysqli_stmt_execute($stmt);
echo "添加数据结果:{$result}";

//重新赋值 再次执行
$username = '李磊';
$age = 22;
$sex = '男';
$result = mysqli_stmt_execute($stmt);
echo "添加数据结果:{$result}";

mysqli_stmt_close($stmt); // 释放资源

mysqli_close($conn); // 关闭数据库连接